package com.xy.controller.admin;

import com.xy.base.RestResponse;
import com.xy.domain.Department;
import com.xy.repository.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/department")
public class DepartmentController {
    @Autowired
    private DepartmentMapper departmentMapper;


    @GetMapping("/list")
    public RestResponse<List<Department>> listDepartments() {
        return RestResponse.ok(departmentMapper.listDepartements());
    }

    @PutMapping("/add")
    public RestResponse<Void> addDepartment(@RequestBody Department department) {
        departmentMapper.insert(department);
        return RestResponse.ok();
    }

    // 需要考虑级联删除
    /*@DeleteMapping("/del")
    public RestResponse<Void> addDepartment(@RequestBody Department department) {
        departmentMapper.insert(department);
        return RestResponse.ok();
    }*/

}
